package cn.livingCloud.service.impl.operation;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.dto.EmployeeFormDto;
import cn.livingCloud.entity.core.Employee;
import cn.livingCloud.repository.EmployeeMapper;
import org.apache.commons.lang.StringUtils;

/**
 * Created by DingJie on 2016/5/31.
 */
public class EmployeeFormDtoUpdater {
    protected transient EmployeeMapper mapper = BeanProvider.getBean(EmployeeMapper.class);
    private EmployeeFormDto formDto;

    public EmployeeFormDtoUpdater(EmployeeFormDto formDto) {
        this.formDto = formDto;
    }

    public void update() {
        String uuid = formDto.getUuid();
        if (StringUtils.isEmpty(uuid)) {
            Employee employee = new Employee();
            formDto.update(employee);
            mapper.insert(employee);
        } else {
            Employee employee = mapper.selectByPrimaryKey(uuid);
            formDto.update(employee);
            mapper.updateByPrimaryKey(employee);
        }
    }
}
